clear
use "C:\Users\amel\Documents\Political Effects of Land-Use Regulation\nhhouses.dta"  /*change path as needed*/
sum yearsold
sort name
encode name, gen(townid)
sort yearsold
gen houseage=yearsold-yearbuilt
drop if missing(name)
sum houseage
replace houseage=0 if houseage<0
sort yearbuilt
sum yearbuilt
drop if yearbuilt>2017
drop if yearbuilt<1700
hist yearbuilt
gen lnage=ln(houseage+1)
gen lnprice=ln(price)
gen lnbed=ln(beds+1)
gen lnbath=ln(baths+1)
gen lnsqft=ln(squarefeet+1)
gen lnlot=ln(lotsize+1)
gen tenacre=0
replace tenacre=1 if lotsize>435602
/*obtain credible coefficient estimates on house attributes, appendix table 5*/
xi: reg lnprice lnage lnbed lnbath lnsqft lnlot tenacre i.townid i.years, cluster(townid)
/*generate predicted house prices using credible attribute coefficient estimates, but excluding town dummies*/
gen xb=7-.068*lnage+.001*lnbed+.31*lnbath+.523*lnsqft+.0367*lnlot+.173*tenacre+.19*_Iyearsold_1997+.24*_Iyearsold_1998+.31*_Iyearsold_1999+.4*_Iyearsold_2000+.4*_Iyearsold_2001+.68*_Iyearsold_2002+.78*_Iyearsold_2003+.89*_Iyearsold_2004+.96*_Iyearsold_2005+.97*_Iyearsold_2006+.94*_Iyearsold_2007+.84*_Iyearsold_2008+.73*_Iyearsold_2009+.72*_Iyearsold_2010+.67*_Iyearsold_2011+.66*_Iyearsold_2012+.71*_Iyearsold_2013+.75*_Iyearsold_2014+.8*_Iyearsold_2015+.84*_Iyearsold_2016+.82*_Iyearsold_2017
/*generate excess price measure*/
gen resid=lnprice-xb
sum xb resid
hist resid
gen period=0
replace period=1 if years>2006 & years<2013
replace period=2 if years>2012
save "C:\Users\amel\Documents\Political Effects of Land-Use Regulation\nhhouse2.dta", replace
